package com.zjh.elktest;

import org.apache.http.HttpHost;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;

import java.io.IOException;

public class GetDoc {
    public static void main(String[] args) throws IOException {
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("10.50.3.20", 9200, "http")));

        GetRequest request=new GetRequest("javatestindex","_doc","1");

        //不获取返回的 _source上下文
        request.fetchSourceContext(new FetchSourceContext(false));
        request.storedFields("_none_");

        boolean exists = client.exists(request, RequestOptions.DEFAULT);
        System.out.println(exists);

        //获得文档信息
//        GetRequest getRequest=new GetRequest("javatestindex","_doc","1");
//        GetResponse getResponse=client.get(getRequest,RequestOptions.DEFAULT);
//        System.out.println(getResponse.getSourceAsString());
//        System.out.println(getResponse);
    }
}
